package net.toocruel.iqismart.web.controller.admin;

import net.toocruel.iqismart.service.ResourceService;
import net.toocruel.iqismart.web.controller.base.AbstractBaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Description
 * @Auther sty
 * @createTime 2018/4/28 上午11:55
 */
@Controller
@RequestMapping("admin")
public class AdminIndexController extends AbstractBaseController {

    @Autowired
    private ResourceService resourceService;

    @RequestMapping("login")
    public String login(HttpServletRequest request, HttpServletResponse response){
        return "admin/account/login";
    }

    @RequestMapping("index")
    public String index(){
        return "admin/index/index";
    }

    @RequestMapping("index/sidebar")
    @ResponseBody
    public String sidebar(HttpServletRequest request, HttpServletResponse response,@RequestParam(defaultValue = "0") Integer collapse){
        Cookie sidebar_collapse = new Cookie("sidebar_collapse", null);
        sidebar_collapse.setMaxAge(0);
        sidebar_collapse.setPath("/");
        response.addCookie(sidebar_collapse);

        sidebar_collapse = new Cookie("sidebar_collapse", collapse+"");
        sidebar_collapse.setMaxAge(Integer.MAX_VALUE);
        sidebar_collapse.setPath("/");
        response.addCookie(sidebar_collapse);

        return "ok";
    }
}
